//=====================================================
//			 		          Vector.cpp
//		      Implementacao da classe Vector3D
//  		     Arquivo criado em 12/12/2010
//		     Microsoft Visual Studio C++ 2008
//
//				     Thiago Bragante Macedo
//              tmacedo29@gmail.com
//=====================================================


#include <vector3d.h>
#include <math.h>

Vector3D::Vector3D ()
{
  
}

Vector3D::Vector3D ( const float& x, const float& y, const float& z )
{
  pos.Coord( x, y, z );
}
void Vector3D::SetX  ( const float& x )
{
  pos.SetX( x );
}
void Vector3D::SetY  ( const float& y )
{
  pos.SetY( y );
}
void Vector3D::SetZ  ( const float& z )
{
  pos.SetZ( z );
}
void Vector3D::Coord ( const float& x, const float& y, const float& z )
{
   pos.Coord( x, y, z );
}
const XYZ& Vector3D::Coord ( void )
{
  return pos.Coord();
}

void  Vector3D::Subtract( const Vector3D& other )
{
  pos.SetX( (pos.X() - other.X()) );
  pos.SetY( (pos.Y() - other.Y()) );
  pos.SetZ( (pos.Z() - other.Z()) );
}


void  Vector3D::Sum ( const Vector3D& other )
{
  pos.SetX( pos.X() + other.X() );
  pos.SetY( pos.Y() + other.Y() );
  pos.SetZ( pos.Z() + other.Z() );
}


void Vector3D::Divide ( const float& scalar )
{
  pos.SetX( pos.X() / scalar );
  pos.SetY( pos.Y() / scalar );
  pos.SetZ( pos.Z() / scalar );
}


void Vector3D::Cross ( const Vector3D& other )
{
  pos.SetX ( ( pos.Y() * other.Z() ) - ( pos.X() * other.Y() ) );

  pos.SetY ( ( pos.Z() * other.X() ) - ( pos.X() * other.Z() ) );

  pos.SetZ ( ( pos.X() * other.Y() ) - ( pos.Y() * other.X() ) );
}

void Vector3D::Normalize ( void )
{
  float magnitude = sqrt( (pos.X()*pos.X()) + (pos.Y()*pos.Y()) + (pos.Z()*pos.Z()) );
  pos.SetX( pos.X() / magnitude );
  pos.SetY( pos.Y() / magnitude );
  pos.SetZ( pos.Z() / magnitude );
}

const float Vector3D::X(void) const
{
  return pos.X();
}

const float Vector3D::Y(void) const
{
  return pos.Y();
}

const float Vector3D::Z(void)  const
{
  return pos.Z();
}


